Fix cases where a registry is not updated
authorAlex Crichton <alex@alexcrichton.com>
Fri, 19 Dec 2014 21:43:21 +0000 (13:43 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 19 Dec 2014 21:43:21 +0000 (13:43 -0800)
If a registry already knew about a package, but didn't know about newly
published version of a package, then the registry would occasionally not be
updated when it otherwise needed to be.

src/cargo/sources/registry.rs
tests/test_cargo_registry.rs

index 4dabec727ae38e83241ae0498d0937bf29087d91..6566b88fb0642f926eea2ff53560367ab4fd5431 100644 (file)
@@ -464,9 +464,13 @@ impl<'a, 'b> Registry for RegistrySource<'a, 'b> {
         // theory the registry is known to contain this version. If, however, we
         // come back with no summaries, then our registry may need to be
         // updated, so we fall back to performing a lazy update.
-        if dep.get_source_id().get_precise().is_some() &&
-           try!(self.summaries(dep.get_name())).len() == 0 {
-            try!(self.do_update());
+        if dep.get_source_id().get_precise().is_some() {
+            let mut summaries = try!(self.summaries(dep.get_name())).iter().map(|s| {
+                s.0.clone()
+            }).collect::<Vec<_>>();
+            if try!(summaries.query(dep)).len() == 0 {
+                try!(self.do_update());
+            }
         }
 
         let summaries = try!(self.summaries(dep.get_name()));
index bd3dcbb8d76f1b6ee3def4b39ccb6f060900e8d8..2b47923590ae8a5b3be3d4963d47e8f8d49f1c85 100644 (file)
@@ -610,3 +610,43 @@ test!(git_and_registry_dep {
     assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
                 execs().with_status(0).with_stdout(""));
 })
+
+test!(update_publish_then_update {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.5.0"
+            authors = []
+
+            [dependencies]
+            a = "0.1.0"
+        "#)
+        .file("src/main.rs", "fn main() {}");
+    p.build();
+
+    r::mock_pkg("a", "0.1.0", &[]);
+
+    assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
+                execs().with_status(0));
+
+
+    r::mock_pkg("a", "0.1.1", &[]);
+
+    let lock = p.root().join("Cargo.lock");
+    let s = File::open(&lock).unwrap().read_to_string().unwrap();
+    File::create(&lock).unwrap().write_str(s.replace("0.1.0", "0.1.1").as_slice())
+                       .unwrap();
+    println!("second");
+
+    fs::rmdir_recursive(&p.root().join("target")).unwrap();
+    assert_that(p.process(cargo_dir().join("cargo")).arg("build"),
+                execs().with_status(0).with_stdout(format!("\
+{updating} [..]
+{downloading} a v0.1.1 (registry file://[..])
+{compiling} a v0.1.1 (registry [..])
+{compiling} foo v0.5.0 ({dir})
+", updating = UPDATING, downloading = DOWNLOADING, compiling = COMPILING,
+   dir = p.url()).as_slice()));
+
+})